﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.storage.ui {
    import flash.events.*;
    import flash.display.*;
    import flash.utils.*;
    import org.aswing.*;
    import Classes.*;
    import __AS3__.vec.*;
    import org.aswing.geom.*;
    import Display.MarketUI.*;
    import Display.InventoryUI.*;
    import Modules.storage.*;
    import Classes.gates.*;
    import Display.aswingui.*;

    public class StorageCatalogUI extends InventoryCatalogUI {

        public static const RIGHT_MARGIN:int = 50;
        public static const TOP_INSET_HEIGHT:int = 50;
        public static const CAPACITY_TEXT_SIZE:int = 14;
        public static const SHELF_COLS:int = 5;
        public static const SHELF_ROWS:int = 2;

        protected var m_capacityLabel:JLabel;
        protected var m_storageUnit:BaseStorageUnit;

        public function StorageCatalogUI(){
            m_catalogTitle = ZLoc.t("Dialogs", "ItemStorage_Title");
        }
        override protected function get assets():Dictionary{
            return (StorageView.assetDict);
        }
        public function get container():StorageView{
            return ((m_catalog as StorageView));
        }
        override public function init(_arg1:String, _arg2:Catalog, _arg3:String, _arg4:Boolean, _arg5:String):void{
            var _local6:StorageView = (_arg2 as StorageView);
            if (_local6.storageKey == "warehouse_deluxe"){
                m_doHighlight = true;
            };
            this.m_storageUnit = Global.player.storageComponent.getStorageUnit(_local6.storageType, _local6.storageKey);
            super.init(_arg1, _arg2, _arg3, _arg4, _arg5);
        }
        override public function switchType(_arg1:String):void{
            if (m_shelf != null){
                m_centerPanel.remove(m_shelf);
            };
            removeListeners();
            var _local2:StorageType = StorageView.getStorageTypeFromCatalogType(_arg1);
            var _local3:String = StorageView.getStorageKeyFromCatalogType(_arg1);
            this.m_storageUnit = Global.player.storageComponent.getStorageUnit(_local2, _local3);
            m_items = this.makeItemsFromStorage();
            m_shelf = new StorageScrollingList(m_items, StoredItemCellFactory, 0, SHELF_COLS, SHELF_ROWS);
            ASwingHelper.prepare(m_shelf);
            m_centerPanel.append(m_shelf);
            m_centerPanel.setPreferredHeight((SHELF_ROWS * StoredItemCellFactory.getDefaultCellHeight()));
            this.updateStorageCapacityText();
            addListeners();
            ASwingHelper.prepare(m_centerPanel);
        }
        override protected function makeTopTabs(_arg1:Array=null):void{
            m_topLeftPanel.append(ASwingHelper.horizontalStrut(INVENTORY_CLOSE_BUTTON_WIDTH));
            m_topLeftPanel.append(makeTitlePanel());
            m_topLeftPanel.append(makeCloseButtonPanel());
            m_tabsPanel.append(ASwingHelper.horizontalStrut(10));
            m_tabsPanel.append(this.makeCrewButtonPanel());
            m_tabsPanel.append(ASwingHelper.verticalStrut(36));
            m_topPanel.append(m_topLeftPanel);
            m_topPanel.append(m_tabsPanel);
            m_topPanel.append(ASwingHelper.verticalStrut(5));
            m_topPanel.append(this.makeStorageCapacityText());
            ASwingHelper.prepare(m_topPanel);
        }
        override protected function makeBackground():void{
            var _local1:DisplayObject = (new EmbeddedArt.storage_bg() as DisplayObject);
            var _local2:MarginBackground = new MarginBackground(_local1);
            this.setBackgroundDecorator(_local2);
            this.setPreferredSize(new IntDimension(_local1.width, (_local1.height + TOP_INSET_HEIGHT)));
            ASwingHelper.prepare(this);
        }
        protected function makeCrewButtonPanel():JPanel{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.RIGHT);
            _local1.setPreferredWidth(this.width);
            _local1.setMaximumWidth(this.width);
            var _local2:String = ZLoc.t("Dialogs", "ItemStorage_AddCrewButton");
            var _local3:CustomButton = new CustomButton(_local2, null, "GreenButtonUI");
            _local3.addActionListener(this.onClickCrewButton, 0, false);
            _local1.appendAll(_local3, ASwingHelper.horizontalStrut(RIGHT_MARGIN));
            return (_local1);
        }
        protected function makeStorageCapacityText():JPanel{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.RIGHT);
            this.m_capacityLabel = ASwingHelper.makeLabel("", EmbeddedArt.DEFAULT_FONT_NAME_BOLD, CAPACITY_TEXT_SIZE, 0);
            this.updateStorageCapacityText();
            ASwingHelper.prepare(this.m_capacityLabel);
            _local1.appendAll(this.m_capacityLabel, ASwingHelper.horizontalStrut(RIGHT_MARGIN));
            return (_local1);
        }
        protected function makeItemsFromStorage():Array{
            var _local7:String;
            var _local1:Array = new Array();
            var _local2:int;
            var _local3:int;
            var _local4:int = this.m_storageUnit.capacity;
            var _local5:int = (SHELF_COLS * SHELF_ROWS);
            var _local6:Vector.<String> = this.m_storageUnit.getItemNames();
            for each (_local7 in _local6) {
                _local1.push({
                    item:Global.gameSettings.getItemByName(_local7),
                    storage:this.m_storageUnit
                });
                _local2 = (_local2 + this.m_storageUnit.getItemCountByName(_local7));
                _local3++;
            };
            while (_local2 < _local4) {
                _local1.push({
                    item:StoredItemCellFactory.getDummyOpenItem(),
                    storage:this.m_storageUnit
                });
                _local2++;
                _local3++;
            };
            while ((_local3 % _local5) != 0) {
                _local1.push({
                    item:StoredItemCellFactory.getDummyLockedItem(),
                    storage:this.m_storageUnit
                });
                _local2++;
                _local3++;
            };
            return (_local1);
        }
        protected function onClickCrewButton(_arg1:Event=null):void{
            var _local2:IGate = (m_catalog as StorageView).storageItem.getGate();
            _local2.displayGate();
            this.closeCatalog(null);
        }
        private function updateStorageCapacityText():void{
            var _local1:String = ZLoc.t("Dialogs", "ItemStorage_StorageCapacityText", {
                capacity:this.m_storageUnit.capacity,
                size:this.m_storageUnit.size
            });
            this.m_capacityLabel.setText(_local1);
        }

    }
}//package Modules.storage.ui 
